package org.subject.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.subject.dao.ArticleMapper;
import org.subject.dto.MessageAndUser;
import org.subject.entity.Article;
import org.subject.entity.Message;
import org.subject.entity.Page;
import org.subject.service.ArticleService;
import org.subject.service.MessageService;

import java.util.List;
import java.util.regex.Pattern;

/**
 * 首页竞赛列表
 */
@Controller
public class IndexController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MessageService messageService;

    @Autowired
    private ArticleService articleService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
        int pages = 1;
        List<MessageAndUser> messageAndUsers = messageService.queryMessageList("", "", pages);
        model.addAttribute("list", messageAndUsers);
        int count = messageService.queryMessageCount("", "");
        Page page = new Page();
        page.setTotalNumber(count);
        model.addAttribute("page", page);

        List<Article> articleList = articleService.queryArticleList("", pages);
        model.addAttribute("articleList", articleList);
        return "index";
    }
}
